package com.pucong.gitee.database.backup.database.controller;

import com.pucong.gitee.database.backup.common.entity.DatabaseTable;
import com.pucong.gitee.database.backup.database.service.OperationDataTableService;
import com.pucong.gitee.database.backup.database.vo.*;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @company www.louddt.com
 * @create 2020-06-23
 */
@RestController
@RequestMapping("/operation/dataTable")
@Api(value = "数据表操作-API ", tags = "5. 数据表操作 API")
public class OperationDataTableController {

    @Autowired
    private OperationDataTableService operationDataTableService;

    @GetMapping("/getTableList/{databaseId}")
    @ApiOperation(value = "501根据数据库id获取表信息")
    public Res<List<DatabaseTable>> getTableList(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId, DatabaseVo databaseVo){
        List<DatabaseTable> databaseTableList = operationDataTableService.getTableList(databaseId, databaseVo);
        return Res.ok(databaseTableList);
    }

    @PostMapping("/renameDataTable/{databaseId}")
    @ApiOperation(value = "502根据数据库id和数据库名称删除表")
    public Res<Boolean> renameDataTable(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId,@RequestBody RenameDataTable renameDataTable){
        Boolean aBoolean = operationDataTableService.renameDataTable(databaseId, renameDataTable);
        return Res.ok(aBoolean);
    }

    @DeleteMapping("/deleteDataTable/{databaseId}")
    @ApiOperation(value = "503根据数据库id和数据库名称删除表")
    public Res<Boolean> deleteDataTable(@ApiParam("数据库id")@PathVariable("databaseId") String databaseId, @ApiParam("数据库id") @RequestBody DeleteDataTable dataTable){
        Boolean aBoolean = operationDataTableService.deleteDataTable(databaseId, dataTable);
        return Res.ok(aBoolean);
    }
}
